﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Common;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Data;

public partial class AjaxXml_Update_Cemetery_AddNumid : BasePage
{
    protected int id = 0;
    protected int lyid = 0;
    protected string lyname = "";
    protected string CemeteryNumId = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Request["lyid"] != null)
        {
            lyid = StringHelper.isNumber_int(Request["lyid"]);
        }
        Cemetery_Model lymd = Cemetery_Bll.CreateNew.GetModel(lyid);
        if (lymd.Id <= 0)
        {
            Response.Write(-2);//陵园不存在
            Response.End();
        }



        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"]);
        }
        Cemetery_AddNumId_Model NumMd = Cemetery_AddNumId_Bll.CreateNew.GetModel(id);
        if (NumMd.Id <= 0)
        {
            Response.Write(-3);//当前所对应的墓点不存在
            Response.End();
        }

        if (Request["lyname"] != null)
        {
            lyname = Request["lyname"].ToString();
        }
        if (lyname + "" != "")
        {
            Cemetery_Bll.CreateNew.filterUpdate(" names='" + lyname + "' ", " id=" + lyid);
        }

        if (Request["CemeNumValue"] != null)
        {
            if (!StringHelper.Str_IsInt(Request["CemeNumValue"].ToString(), out CemeteryNumId))
            {
                Response.Write(-1);//纪念馆号不能为空
                Response.End();
            }
        }
        DataTable dt = Memorial_Bll.CreateNew.GetDataTable(" where Numid='" + CemeteryNumId + "'");
        if (dt.Rows.Count <= 0)
        {
            Response.Write(-4);//纪念馆号不存在
            Response.End();
        }
        List<Cemetery_AddNumId_Model> list = Cemetery_AddNumId_Bll.CreateNew.GetData(" Userid=" + Base_GetUserInfo.UserId + " and cemeteryId=" + lyid + " and numid=" + CemeteryNumId);
        if (list.Count > 0)
        {
            if (id != list[0].Id)
            {
                Response.Write("-5");//当前输入的纪念馆号已经存在
                Response.End();
            }
        }
        Cemetery_AddNumId_Bll.CreateNew.Update(" numid='" + CemeteryNumId + "' ", " id=" + id);


    }
}
